package com.atguigu.a_comparator;

import java.util.Comparator;
import java.util.TreeSet;

public class Demo {
    public static void main(String[] args) {
        //创建TreeSet集合存学生对象
        //TreeSet<E>(Comparator<E> comparator)
//        Comparator<Student> comparator = new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o1.getAge() - o2.getAge();
//            }
//        };
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });

        ts.add(new Student("张三",18));
        ts.add(new Student("李四",17));
        ts.add(new Student("王五",19));

        System.out.println("ts = " + ts);
    }
}
